package com.atguigu.realtime.udf;

import com.atguigu.realtime.common.GmallConstant;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/2/18 9:51
 */
@FunctionHint(output = @DataTypeHint("ROW<source string, ct bigint>"))
public class KeyWordProductUdtf extends TableFunction<Row> {
    public void eval(Long clickCount, Long cartCount, Long orderCount) {
        
        if(clickCount > 0){
            collect(Row.of(GmallConstant.KEYWORD_CLICK, clickCount));
        }
        
        if(cartCount > 0){
            collect(Row.of(GmallConstant.KEYWORD_CART, cartCount));
        }
        
        if(orderCount > 0){
            collect(Row.of(GmallConstant.KEYWORD_ORDER, orderCount));
        }
    }
}
